<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var Magento\Braintree\Block\Payment $block */

$code = $block->escapeHtml($block->getCode());

?>
<script>
    //<![CDATA[
    require(
        [
            'Magento_Braintree/js/braintree',
            'jquery',
            'domReady!'
        ], function(Braintree, $) {
            var config = <?php /* @noEscape */ echo $block->getPaymentConfig(); ?>,
                payment,
                form = $('#payment_form_<?php /* @noEscape */ echo $code; ?>');

            config.active = form.length > 0 && !form.is(':hidden');
            payment = new Braintree(config);
        });
    //]]>
</script>
